<?php
require_once 'Zend/Db/Table/Abstract.php';
class AdminModel extends Zend_Db_Table_Abstract
{
	protected $_name = 'admin';
	protected $_id = 'id';
	
    public function admin($params=NULL, $options=NULL){
		$db = Zend_Registry::get('connectDB');
		$mySql = $db->select()
					->from('admin');
		$list = $db->fetchAll($mySql);
      
        if(isset($options['json'])){
            return $this->jqueryTable($list);
       }
      
        return $list;
	}
   
   public function jqueryTable($data=array()){
        $totalRecords= count($data);
        $output= array(
        "sEcho"=>5,
        "iTotalRecords"=> $totalRecords,
        "iTotalDisplayRecords"=> 5,
        "aaData"=> array()
        );
        
        foreach ($data as $values){
           	$button_html = "<center><a href='/admin/admin/edit?id=".$values['id']."' class='tooltip' title='Edit Account'>";
            $button_html .= "<img alt='edit account' src='/images/adminbase/icons/16/comment_edit.png'></a></center>";
           	$check = "<center><input type='checkbox' name='checks[]' value=".$values['id']."></center>";
           
            $rows= array();
          
            $rows[]= $values['name'];
            $rows[]= $values['sunnet_email'];
            $rows[]= $values['role'];
            $status = $values['status'] ? 'ON': 'OFF';
            $rows[] = $button_html;
            $rows[]= $status;
            $rows[]= $check;
            $output['aaData'][] = $rows;
        }
        
       return json_encode($output);
    }
   
   public function id_admin($id){
		$db = Zend_Registry::get('connectDB');
		$mySql = $db->select()
					->from('admin')
					->where("id =?",$id);
		$list = $db->fetchAll($mySql);
		return $list;
	}
	
	public function get_email_admin($email){
		$db = Zend_Registry::get('connectDB');
		$mySql = $db->select()
					->from('admin')
					->where("sunnet_email =?",$email);
		$list = $db->fetchAll($mySql);
		return $list;
	}
}